package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("userOrdersController")
@RequestMapping("/user/order")
@ApiOperation("订单相关接口")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;
    /**
     * 用户下单
     */
    @PostMapping("/submit")
    @ApiOperation(value = "用户下单")
    public Result<OrderSubmitVO> orderSubmit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = ordersService.placeAnOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
//        log.info("订单支付：{}", ordersPaymentDTO);
//        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
//        log.info("生成预支付交易单：{}", orderPaymentVO);
//        return Result.success(ordersService);

        ordersService.payment(ordersPaymentDTO);
        return Result.success();
    }

    /**
     * 历史订单查询
     */
    @GetMapping("/historyOrders")
    @ApiOperation(value = "历史订单查询")
    public Result<PageResult> page( OrdersPageQueryDTO ordersPageQueryDTO){

        PageResult list = ordersService.page(ordersPageQueryDTO);
        return Result.success(list);

    }
    /**
     * 查询订单详情
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation(value = "查询订单详情")
    public  Result<OrderVO> getOrderDetail(@PathVariable Long id){
        OrderVO orderVO = ordersService.getOrderDetail(id);
        return Result.success(orderVO);
    }
    /**
     * 取消订单
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation(value = "取消订单")
    public Result<String> cancelOrder(@PathVariable Long id) throws Exception {
        ordersService.cancelOrder(id);
        return Result.success();
    }

    /**
     * 再来一单
     */
    @PostMapping("repetition/{id}")
    @ApiOperation(value = "再来一单")
    public Result<String> againOrder(@PathVariable Long id){
        ordersService.againOrder(id);
        return Result.success();
    }

    /**
     * 用户催单
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation(value = "用户催单")
    public Result<String> reminder(@PathVariable Long id){
        ordersService.reminder(id);
        return Result.success();
    }
}













